package cn.hc.mq.boot.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/producer")
@Slf4j
public class ProducerController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping(path = "/test/sync")
    public String sync(String name) {
        Message msg = MessageBuilder.withPayload("springboot发送同步消息:" + name).build();
        log.info("发送消息1：{}", name);
        rocketMQTemplate.send("helloBoot", msg);
        return "ok-sync-" + name;
    }

    @GetMapping(path = "/test/sync2")
    public String sync2(String name) {
        Message msg = MessageBuilder.withPayload("springboot发送同步消息:" + name).build();
        log.info("发送消息2：{}", name);
        rocketMQTemplate.send("helloBoot2", msg);
        return "ok-sync2-" + name;
    }

}
